<template>
  <div id="app">
    <h2>测试题</h2>
    <subject :arr="list" @submitNum="submitFn"></subject>
    <div>
      <flag :arr="list"></flag>
    </div>
  </div>
</template>

<script>
import subject from "./components/Subject";
import flag from "./components/Flag";
export default {
  components: {
    subject,
    flag,
  },
  data() {
    return {
      list: [
        {
          id: 1,
          val: "",
          num1: Math.floor(Math.random() * 100),
          num2: Math.floor(Math.random() * 100),
          finished: "未完成",
        },
        {
          id: 2,
          val: "",
          num1: Math.floor(Math.random() * 100),
          num2: Math.floor(Math.random() * 100),
          finished: "未完成",
        },
        {
          id: 3,
          val: "",
          num1: Math.floor(Math.random() * 100),
          num2: Math.floor(Math.random() * 100),
          finished: "未完成",
        },
        {
          id: 4,
          val: "",
          num1: Math.floor(Math.random() * 100),
          num2: Math.floor(Math.random() * 100),
          finished: "未完成",
        },
      ],
      finish: "",
    };
  },
  methods: {
    submitFn(ind) {
      this.finish = this.list[ind].num1 + this.list[ind].num2;
    
      if (this.finish != this.list[ind].val) {
      
        this.list[ind].finished = "错误";
      } else if (this.finish == this.list[ind].val) {
        this.list[ind].finished = "成功";
      }
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}
#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>